package powerdev.servlet;

import java.io.IOException;
import java.sql.Date;
import java.sql.Time;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import powerdev.excepcion.DAOExcepcion;
import powerdev.negocio.GestionPublicidad;

/**
 * Servlet implementation class RegistraPublicidad
 */
public class RegistraPublicidad extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistraPublicidad() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
				GestionPublicidad neg = new GestionPublicidad();
				
				String no_Titulo =request.getParameter("Txt_NoPublicidad");
				String tx_Contenido =request.getParameter("Txt_Contenido");
				Date fe_inicioVigencia=Date.valueOf(request.getParameter("Txt_Feinicio"));
				Date fe_FinVigencia=Date.valueOf(request.getParameter("Txt_Fefin"));
				double ss_Tarifa =Double.valueOf(request.getParameter("Txt_Importe"));
				int nu_Click =Integer.parseInt(request.getParameter("cmbLocal"));
				
				
				try {
					neg.insertarPublicidad(no_Titulo, tx_Contenido, fe_inicioVigencia,
							fe_FinVigencia, ss_Tarifa, nu_Click, 1, true);
					
					request.setAttribute("MENSAJE", "Se registro correctamente.");
					
				} catch (DAOExcepcion e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					request.setAttribute("MENSAJE", e1.getMessage());
				}

				RequestDispatcher rd = request
						.getRequestDispatcher("Publicidad.jsp");
				rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
